package com.itheima.reggie.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.itheima.reggie.common.ResultInfo;
import com.itheima.reggie.domain.Order;

import com.itheima.reggie.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

// 订单模块
@RestController
@RequestMapping("/order")
public class OrderController {
    @Autowired
    private OrderService orderService;

    // 用户下单
    @PostMapping("/submit")
    public ResultInfo submit(@RequestBody Order order) { // 1.接收参数
        // 2.调用service生成订单
        orderService.submit(order);
        // 3.返回结果
        return ResultInfo.success();
    }


    //分页查询订单
    @GetMapping("/userPage")
    public ResultInfo findByPage(
            @RequestParam(value = "page", defaultValue = "1") Integer pageNum,
            @RequestParam(value = "pageSize", defaultValue = "5") Integer pageSize
    ) {
        //调用service查询
        Page<Order> page = orderService.findByPage(pageNum, pageSize);
        //返回结果
        return ResultInfo.success(page);
    }
}
